package com.ruoyi.system.controller;

import java.util.Arrays;
import java.util.List;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.api.domain.SysOperUrl;
import com.ruoyi.system.service.ISysOperUrlService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 日志配置Controller
 * 
 * @author lcj
 * @date 2025-05-16
 */
@RestController
@RequestMapping("/operlogurl")
public class SysOperUrlController extends BaseController
{
    @Autowired
    private ISysOperUrlService sysOperUrlService;

    /**
     * 刷新日志
     */
    @GetMapping("/getRefreshCache")
    public AjaxResult getRefreshCache() {
        sysOperUrlService.getRefreshCache();
        return AjaxResult.success("日志刷新成功");
    }

    /**
     * 查询日志配置列表
     */
    @RequiresPermissions("system:operlogurl:list")
    @GetMapping("/list")
    public TableDataInfo list(SysOperUrl sysOperUrl)
    {
        startPage();
        List<SysOperUrl> list = sysOperUrlService.list(Wrappers.query(sysOperUrl));
        return getDataTable(list);
    }

    /**
     * 导出日志配置列表
     */
    @RequiresPermissions("system:operlogurl:export")
    @Log(title = "日志配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysOperUrl sysOperUrl)
    {
        List<SysOperUrl> list = sysOperUrlService.list(Wrappers.query(sysOperUrl));
        ExcelUtil<SysOperUrl> util = new ExcelUtil<SysOperUrl>(SysOperUrl.class);
        util.exportExcel(response, list, "日志配置数据");
    }

    /**
     * 获取日志配置详细信息
     */
    @RequiresPermissions("system:operlogurl:query")
    @GetMapping(value = "/getInfo/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(sysOperUrlService.getById(id));
    }

    /**
     * 新增日志配置
     */
    @RequiresPermissions("system:operlogurl:add")
    @Log(title = "日志配置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody SysOperUrl sysOperUrl)
    {
        return toAjax(sysOperUrlService.save(sysOperUrl));
    }

    /**
     * 修改日志配置
     */
    @RequiresPermissions("system:operlogurl:edit")
    @Log(title = "日志配置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody SysOperUrl sysOperUrl)
    {
        return toAjax(sysOperUrlService.updateById(sysOperUrl));
    }

    /**
     * 删除日志配置
     */
    @RequiresPermissions("system:operlogurl:remove")
    @Log(title = "日志配置", businessType = BusinessType.DELETE)
	@GetMapping("/remove/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysOperUrlService.removeByIds(Arrays.asList(ids)));
    }
}
